<?php
/**
 * 订单评价表
 * @author RenJianHong
 * @date 2021-8-3 9:28
 */
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderCommentTable extends Migration
{
    public $tableName = "order_comment";

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(!Schema::hasTable($this->tableName)) $this->create();
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }

    /**
     * 执行创建表
     */
    private function create()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->engine = 'InnoDB';      // 设置存储引擎
            $table->charset = 'utf8';       // 设置字符集
            $table->collation  = 'utf8_general_ci';       // 设置排序规则
            $table->index('order_id');//普通索引

            $table->id();
            $table->integer("order_id")->nullable(false)->default(0)->comment("订单ID");
            $table->integer("order_detail_id")->nullable(false)->default(0)->comment("订单详情ID");
            $table->integer("goods_id")->nullable(false)->default(0)->comment("商品ID");
            $table->integer("user_id")->nullable(false)->default(0)->comment("用户ID");
            $table->decimal("score",10,2)->nullable(false)->default(0)->comment("评分");
            $table->longText("content")->nullable(true)->comment("评价内容");
            $table->longText("pic_list")->nullable(true)->comment("商品图片");
            $table->longText("reply_content")->nullable(true)->comment("回复评价内容");
            
            $table->tinyInteger("is_hide")->nullable(false)->default(0)->comment("是否隐藏 0--否 1--是");
            $table->tinyInteger("is_delete")->nullable(false)->default(0)->comment("是否删除 0--否 1--是");

            $table->timestamps();
            
        });
        DB::statement("ALTER TABLE zzkj_{$this->tableName} comment '订单评价表'");
    }
}
